package com.hr.reactive.threading;

import com.hr.reactive.common.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;

public class Lec01Defauledemo {
    private static final Logger log = LoggerFactory.getLogger(Lec01Defauledemo.class);

    public static void main(String[] args) {

        var f = Flux.create(fluxSink -> {
                    for (int i = 0; i < 3; i++) {
                        log.info("genering:{}", i);
                        fluxSink.next(i);
                    }
                    fluxSink.complete();
                })
                .doOnNext(v -> log.info("value is :{}", v));

      f
             .doFirst(()->log.info("first 1"))
              .subscribeOn(Schedulers.boundedElastic())
              .doFirst(()->log.info("first 2"))
              .subscribe(Utils.subscriber());
      Utils.sleepSeconds(3000);

    }
}
